package com.mzw.huaxiarealestatebackend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mzw.huaxiarealestatebackend.entity.BackPage;
import com.mzw.huaxiarealestatebackend.entity.Client;
import com.mzw.huaxiarealestatebackend.entity.ProjectRecord;
import com.mzw.huaxiarealestatebackend.dao.ProjectRecordDao;
import com.mzw.huaxiarealestatebackend.service.ProjectRecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (ProjectRecord)表服务实现类
 *
 * @author makejava
 * @since 2023-12-22 00:03:04
 */
@Service("projectRecordService")
public class ProjectRecordServiceImpl implements ProjectRecordService {
    @Resource
    private ProjectRecordDao projectRecordDao;

    /**
     * 模糊查询
     * @param projectRecord
     * @return
     */
    @Override
    public List<ProjectRecord> queryByCondition(ProjectRecord projectRecord) {
        LambdaQueryWrapper<ProjectRecord> lqw = new LambdaQueryWrapper<>();

        lqw.and(wrapper ->
                wrapper.eq(projectRecord.getStfNo() != null, ProjectRecord::getStfNo, projectRecord.getStfNo())
                        .eq(projectRecord.getPjtNo() != null, ProjectRecord::getPjtNo, projectRecord.getPjtNo())
                        .eq(projectRecord.getPcsNo() != null, ProjectRecord::getPcsNo, projectRecord.getPcsNo())
                        .eq(projectRecord.getFileStatus() != null, ProjectRecord::getFileStatus, projectRecord.getFileStatus())
                        .eq(projectRecord.getPrcdFinishstatus() != null, ProjectRecord::getPrcdFinishstatus, projectRecord.getPrcdFinishstatus())
        );

        List<ProjectRecord> projectRecords = this.projectRecordDao.selectList(lqw);
        return projectRecords;
    }

    /**
     * 通过ID查询单条数据
     *
     * @param prcdNo 主键
     * @return 实例对象
     */
    @Override
    public ProjectRecord queryById(String prcdNo) {
        QueryWrapper<ProjectRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("prcd_no", prcdNo);
        ProjectRecord projectRecord = projectRecordDao.selectOne(queryWrapper);
        return projectRecord;
    }

    /**
     * 分页查询
     * @param current    当前页码
     * @param size      分页大小
     * @return
     */
    @Override
    public BackPage<ProjectRecord> queryByPage(int current, int size) {
        BackPage<ProjectRecord> backPage= new BackPage<>();
        //创建Page对象，传递两个参数：当前页    每页显示记录数
        Page<ProjectRecord> page = new Page<>(current,size);
        //调用mp方法实现分页
        projectRecordDao.selectPage(page,null);
        //IPage<User> pageModel = userMapper.selectPage(page,null);
        backPage.setContentList(page.getRecords());
        backPage.setCurrentPage(page.getCurrent());
        backPage.setTotalPage(page.getPages());
        backPage.setTotalNum(page.getTotal());
        return backPage;
    }

    /**
     * 新增数据
     *
     * @param projectRecord 实例对象
     * @return 实例对象
     */
    @Override
    public boolean insert(ProjectRecord projectRecord) {
        int insert = this.projectRecordDao.insert(projectRecord);
        return insert > 0;
    }

    /**
     * 修改数据
     *
     * @param projectRecord 实例对象
     * @return 实例对象
     */
    @Override
    public boolean update(ProjectRecord projectRecord) {
        int update = this.projectRecordDao.update(projectRecord);
        return update > 0;
    }

    /**
     * 通过主键删除数据
     *
     * @param prcdNo 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String prcdNo) {
        return this.projectRecordDao.deleteById(prcdNo) > 0;
    }
}
